<template>
	<view class="layout">
		<common-title></common-title>
	</view>
	<view class="notice">
		<view class="left">
			<uni-icons type="sound-filled" size="20"></uni-icons>
			<text class="text">说明</text>
		</view>
		<view class="center">
			<text class="tip">{{showtip}}</text>
		</view>
	</view>	
	<view class="img" @click="OnSelectImg">
		<image :src=demopath mode="widthFix"></image>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import {onLoad,onUnload,onReachBottom,onShareAppMessage,onShareTimeline} from "@dcloudio/uni-app";
import { pathToBase64, base64ToPath } from 'image-tools'
const demopath = ref("https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/demo_pro_00.jpeg")
const file_base64 = ref("")
const obj = ref("")
const server_token = ref("db140af0-c1b8-11ee-b115-0242ac110003")
const server_url_api_name = ref("commonAlg")
const showtip = ref("检测电梯视角下的电动车,点击图片上传")
const type = ref("")
onLoad((e)=>{	
	type.value = e.type
	if (type.value === "pro_00_electrickcycle"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/demo_pro_00.jpeg"
		showtip.value = "检测电梯视角下的电动车,点击图片上传"
	}else if (type.value === "pro_01_infrared_boat"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/pro_01_infrared_boat_demo.png"
		showtip.value = "红外线摄像头下的船只检测,点击图片上传"		
	}else if (type.value === "pro_02_infrared_aerial_photo"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/pro_02_demo.jpg"
		showtip.value = "红外线航拍摄像头下的人车检测,点击图片上传"				
	}
	else if (type.value === "pro_03_ship"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/ship.jpeg"
		showtip.value = "可光光摄像头下的船只检测,点击图片上传"				
	}
	else if (type.value === "pro_04_dutycar"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/dutycar_demo.jpeg"
		showtip.value = "巡逻车检测,点击图片上传"				
	}
	

	else if (type.value === "pro_07_phone"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/phone.jpeg"
		showtip.value = "手机检测,点击图片上传"				
	}
	else if (type.value=="pro_09_sleep"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/sleep_demo.jpeg"
		showtip.value = "睡岗检测,点击图片上传"			
	}
	else if (type.value === "pro_10_drone"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/无人机.jpg"
		showtip.value = "无人机检测,点击图片上传"				
	}
	else if (type.value=="pro_11_smoke"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/smoke_demo.jpeg"
		showtip.value = "抽烟检测,点击图片上传"			
	}
	else if (type.value=="pro_13_smokefire"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/烟和火.jpeg"
		showtip.value = "火情监控,点击图片上传"			
	}
	else if (type.value=="pro_15_violence"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/voilence_demo.jpeg"
		showtip.value = "打架检测,点击图片上传"			
	}
	else if (type.value=="pro_16_fall"){
		demopath.value = "https://aitestgo-bj.oss-cn-beijing.aliyuncs.com/docker/alg/uniapp/ui2/fall_demo.jpg"
		showtip.value = "跌倒检测,点击图片上传"			
	}
	
})

const OnSelectImg = async () => {
uni.chooseImage({
					count: 1,
					sizeType: ['compressed'],
					sourceType: ['camera', 'album'],
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						pathToBase64(tempFilePaths[0])
							.then(base64 => {
								let base64String = base64.substring(base64.indexOf(',') + 1)
								file_base64.value = base64String
								let request_data={}
								if (server_url_api_name.value==="commonAlg"){
									request_data["data"]=[										
										server_token.value,
										{
										"data":"data:image/jpeg;base64,"+base64String,
										"name":"p1.jpg",
										//"size":351604,
										},
										{
											"type":type.value
										}
									]
								}
								else{
									request_data["data"]=[
										server_token.value,
										{
										"data":"data:image/jpeg;base64,"+base64String,
										"name":"p1.jpg",
										//"size":351604,
										}
									]
								}
								uni.request({
									url:"https://rd.aitestgo.com/run/" + server_url_api_name.value,
									//url:"http://59.110.163.32:50052/run/" + server_url_api_name.value,
									//url:"http://172.16.75.68:9012/run/" + server_url_api_name.value,
									data:request_data,									
									method:"POST",
									success:res=>{
										//console.log(res)
										obj.value = res.data.data[0]
										//console.log("obj.value:", obj.value)
										if (obj.value.hasOwnProperty("imgUrl")){
											demopath.value=obj.value["imgUrl"]
										}
										else{
											demopath.value = tempFilePaths[0]
										}
										//analysis_res()
										//let newShowHeight = res.data.data[0]["height"]*750/res.data.data[0]["width"]
										//imageStyle.height = `${newShowHeight}rpx`;
										//console.log("image_width:", res.data.data[0]["width"])
										//console.log("image_height:", res.data.data[0]["height"])										
									}
								})
							})
							.catch(error => {
								console.error(error)
							})
					}
				})
};
</script>

<style  lang="scss" scoped>
.notice{
	width: 100%;
	height: 80rpx;
	line-height: 80rpx;
	background: #f9e6f2;
	margin: 0 auto;
	border-radius: 10rpx;
	display: flex;
	border-radius: 10rpx;
	.left{
		width: 140rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		:deep(){
			.uni-icons{
				color:f2fff8 !important;
			}
		}			
		.text{
			color:#555;
			font-weight: 600;
			font-size: 28rpx;
		}
	}
}
.img{
	width:100%;
	image{
		width:100%;
	}
}
</style>
